import time

from selenium.webdriver.common.by import By


class FinanceOperation():
    # 买入零钱理财的操作
    def buyFinance(self, driver, paypassword):
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(5)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td['
                                      '6]/button').click()
        time.sleep(5)
        driver.find_element(By.CSS_SELECTOR, '.layui-layer-content > #password').send_keys(paypassword)
        time.sleep(5)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(6)
        result_buy = driver.find_element(By.XPATH,
                                         '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div').text
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(2)
        return result_buy

    # 买入期限理财的操作
    def buyTermFinance(self, driver, paypassword):
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(5)
        driver.find_element(By.LINK_TEXT, '期限理财').click()
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td['
                                      '8]/button').click()
        time.sleep(5)
        driver.find_element(By.CSS_SELECTOR, '.layui-layer-content > #password').send_keys(paypassword)
        time.sleep(5)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(6)
        result_buy = driver.find_element(By.XPATH,
                                         '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div').text
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(2)
        return result_buy

    # 买入基金广发多元股票
    def buyBuyFund(self, driver, paypassword):
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(5)
        driver.find_element(By.LINK_TEXT, '基金理财').click()
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td['
                                      '9]/button').click()
        time.sleep(5)
        driver.find_element(By.CSS_SELECTOR, '.layui-layer-content > #password').send_keys(paypassword)
        time.sleep(5)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(6)
        result_buy = driver.find_element(By.XPATH,
                                         '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div').text
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(2)
        return result_buy

    # 获取银行卡余额
    def getBankCardMoney(self, driver, result_buy):
        time.sleep(3)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        time.sleep(5)
        driver.find_element(By.LINK_TEXT, '银行卡管理').click()
        time.sleep(5)
        result = driver.find_element(By.CLASS_NAME, 'card-body').text
        result = result[26:-4]
        return result

    # 切换默认银行卡
    def changBank(self, driver):
        time.sleep(3)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        time.sleep(5)
        driver.find_element(By.LINK_TEXT, '银行卡管理').click()
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[3]/div/div/div[1]/ul/li/button[3]').click()
        result = driver.find_element(By.CLASS_NAME, 'card-body').text
        result = result[26:-4]
        return result


        # 获取银行卡余额
    def getBankCardMoney2(self, driver):
        time.sleep(3)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[3]/div/div/div[2]').click()
        time.sleep(5)
        driver.find_element(By.LINK_TEXT, '银行卡管理').click()
        time.sleep(5)
        result = driver.find_element(By.CLASS_NAME, 'card-body').text
        result = result[26:-4]
        return result
